<template>
	<view class="fillBox">
		<view class="title">
			添加经销商
		</view>
		<!-- 填报内容 -->
		<view class="fillContent">
			<view class="fillContentBox">
				<view class="numType">
					<view class="numType1">
						数据类型:
					</view>
					<view class="numType2">
						经销商数据
					</view>
				</view>
				<view class="wire">
					
				</view>
				<view class="nameBox">
					<view class="nameBox1">
						姓名:
					</view>
					<input type="text" v-model="name" class="nameBox2"  placeholder="请输入姓名"/>
				</view>
				<view class="wire">
					
				</view>
				<view class="nameBox">
					<view class="nameBox1">
						电话:
					</view>
					<input type="text" v-model="phone" class="nameBox2"  placeholder="请输入手机号"/>
				</view>
				<view class="wire">
					
				</view>
			
				<view class="nameBoxa">
					<view class="nameBoxa1">
						登录密码:
					</view>
					<input type="text" v-model="model" class="nameBoxa2"  placeholder="请输入登录密码"/>
				</view>
				<view class="wire">
					
				</view>
				<view class="nameBoxa">
					<view class="nameBoxa1">
						所属地担:
					</view>
					<input type="text" v-model="address" :disabled="true" class="nameBoxa2"  placeholder="请输入所属地担"/>
				</view>
				<view class="wire">
					
				</view>
				<view class="nameBoxa">
					<view class="nameBoxa1">
						所属门店:
					</view>
					<view class="uni-list-cell-db" style="flex: 1;">
						<picker @change="bindPickerChange" :value="index" :range="array">
							<view class="uni-input">{{ array[index] }}</view>
						</picker>
					</view>
				</view>
				<view class="wire">
					
				</view>
				<view class="btn" @click="submitClick">
					确定提交
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {regionStoreList,regionAddEdit} from '@/request/api.js';
	export default {
		data() {
			return {
				name:'',//姓名
				phone:'',
				model:'',//购买车型
				remarks:'',
				address:'',
				obj:{},
				array:[],
				index: 0,
				arrayS:[],
				mendianId:''
			};
		},
		onLoad() {
			this.obj = uni.getStorageSync('regionMessage')
			this.address = this.obj.sheng+this.obj.shi+this.obj.qu;
			this.init()
			
		},
		onShow() {
			
		},
		methods:{
			//数据初始化
			init(){
				let _this = this
				regionStoreList().then(res => {
						
						if(res.code==1){
							_this.array=[]
							
							// console.log(res, '123123123123');
							_this.arrayS=res.data;
							
							_this.mendianId= res.data[0].id;
							for(let i=0;i<res.data.length;i++){
								// console.log(res.data[i])
								_this.array.push(res.data[i].stores)
							}
							// console.log(_this.array)
						}
							
						
					})
					.catch(err => {});
			},
			submitClick(){
				let _this = this
				if(_this.name == '' || _this.phone == '' || _this.model == ''){
					uni.showToast({
						title:"请填写完整信息",
						icon:"none"
					})
					return
				}
				let data = {
					regional_id:_this.obj.id,
					store: _this.mendianId,
					name: _this.name,
					mobile: _this.phone,
					password: _this.model,
				};
				regionAddEdit(data)
					.then(res => {
						if (res.code == 1) {
							uni.navigateBack({
								delta: 1
							});
							setTimeout(() => {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}, 1000);
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.target.value);
				let _this =this
				this.index = e.target.value;
				this.arrayS.forEach((item,idnexs) =>{
					if(e.target.value==idnexs){
						_this.mendianId = item.id
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page{
		background-color: #FFFFFF;
	}
	.fillBox{
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 40rpx;
		overflow: hidden;
		position: relative;
		.title{
			width: 100%;
			text-align: center;
			margin-top: 54rpx;
			font-size: 38rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #313233;
		}
		.fillContent{
			width: 100%;
			overflow: hidden;
			.fillContentBox{
				width: 622rpx;
				margin: 30rpx auto 0;
				.numType{
					width: 100%;
					display: flex;
					overflow: hidden;
					.numType1{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						margin-right: 80rpx;
					}
					.numType2{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
					}
				}
				
				.wire{
					width: 100%;
					height: 4rpx;
					background-color:#e9e9ec;
					margin-top: 28rpx;
				}
				.nameBox{
					width: 100%;
					display: flex;
					overflow: hidden;
					margin-top: 40rpx;
					.nameBox1{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						margin-right: 156rpx;
					}
					.nameBox2{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						flex: 1;
					}
				}
				.nameBoxa{
					width: 100%;
					display: flex;
					overflow: hidden;
					margin-top: 40rpx;
					.nameBoxa1{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						margin-right: 84rpx;
					}
					.nameBoxa2{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						flex: 1;
					}
				}
				.remarks{
					width: 100%;
					display: flex;
					overflow: hidden;
					margin-top: 40rpx;
					.remarks1{
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						margin-right: 150rpx;
					}
					.remarks2{
						width: 386rpx;
						height: 230rpx;
						border: 1px solid #e9e9ec;
					}
				}
				.btn{
					width: 460rpx;
					height: 80rpx;
					background: #1855F6;
					border-radius: 40rpx;
					// margin-top: 122rpx;
					margin: 122rpx auto 0;
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #FFFFFF;
					line-height: 80rpx;
					text-align: center;
				}
			}
		}
	}
</style>
